package bookstore.domain;

import static java.lang.System.out;

import java.io.Serializable;

import bookstore.util.In;

@SuppressWarnings("serial")
public class Book implements Serializable{	
	private int code;      
	private String title;    	
	private String writer;  
	private int price; 
	
	public Book() {}	
	
	public int getCode(){
		return code;
	}
	
	public String getTitle(){
		return title;
	}
	
	public int getPrice(){
		return price;
	}	
		
	public String toString(){
		return String.format("[%d] %s| by %s| $%d",code,title,writer,price);
	}	
	
	// input book information
	public boolean setInfo(){		
		// generate new book code.
		if(this.code<1000) this.code = (int)(Math.random()*9999)+1000;
		
		boolean isOK = false;
		do{
			isOK = true;
			title = "";
			writer = "";
			price = 0;
			out.println(MSG.INPUT_BOOK_INFO);
			out.print(MSG.INPUT_BOOK_INFO_DETAIL[0]+": "); title = In.nextLine();
			out.print(MSG.INPUT_BOOK_INFO_DETAIL[1]+": "); writer = In.nextLine();
			out.print(MSG.INPUT_BOOK_INFO_DETAIL[2]+": "); price = In.nextInt();			
			if(title=="" || writer=="" || price<0)	{
				out.println(MSG.FAIL+MSG.INPUT_BOOK_INFO_INVALID);
				isOK = false;
			}
		}while(!isOK);
		
		return isOK;
	}
}
